import '../../../app_files.dart';
import 'package:azlistview/azlistview.dart';

class PatrolPlanModel extends ISuspensionBean {
  final String planName;
  final String planValue;
  final String jobName;

  @override
  String getSuspensionTag() => jobName;

  PatrolPlanModel({
    this.planName,
    this.planValue,
    this.jobName,
  });

  static fromJson(json) {
    return PatrolPlanModel(
      planName: CommonUtils.checkNullToString(json['pttaskName']),
      jobName: CommonUtils.checkNullToString(json['pttaskPtplanname']),
      planValue: CommonUtils.checkNullToString(json['pttaskId']),
    );
  }
}

class PatrolAreaModel {
  final String itemID;
  final String areaName;
  final String status;
  final String areaID;
  final String planID;
  final String needCheckNum;
  final String checkedNum;
  final String checkRate;
  final String normalNumber;
  final String generalNumber;
  final String seriousNumber;
  final String fixNumber;
  final String planName;

  double get checkRateValue {
    double value = double.tryParse(checkRate) ?? 0.0;
    if (value == 0) return 0;
    return value / 100;
  }

  const PatrolAreaModel({
    this.areaName,
    this.itemID,
    this.status,
    this.areaID,
    this.planID,
    this.needCheckNum,
    this.checkedNum,
    this.checkRate,
    this.normalNumber,
    this.generalNumber,
    this.seriousNumber,
    this.fixNumber,
    this.planName,
  });

  static fromJson(json) {
    return PatrolAreaModel(
      itemID: CommonUtils.checkNullToString(json['ptareaId']),
      areaName: CommonUtils.checkNullToString(json['ptareaAreaname']),
      areaID: CommonUtils.checkNullToString(json['ptareaAreaid']),
      planID: CommonUtils.checkNullToString(json['ptareaPttaskid']),
      status: CommonUtils.checkNullToString(json['ptareaStatus']),
      needCheckNum: CommonUtils.checkNullToString(json['waitChecked']),
      checkedNum: CommonUtils.checkNullToString(json['checked']),
      checkRate: CommonUtils.checkNullToString(json['ptareaCheckedrate']),
      normalNumber: CommonUtils.checkNullToString(json['normal']),
      generalNumber: CommonUtils.checkNullToString(json['hidden']),
      seriousNumber: CommonUtils.checkNullToString(json['maintenance']),
      fixNumber: CommonUtils.checkNullToString(json['study']),
      planName: CommonUtils.checkNullToString(json['pttaskName']),
    );
  }

  String get statusName {
    switch (status) {
      case '1':
        return '待巡检';
      case '2':
        return '巡检中';
      case '3':
        return '已完成';
      case '4':
        return '已中止';
      case '5':
        return '已关闭';
      default:
        return '未知';
    }
  }
}

class PatrolOrderItemModel {
  PatrolOrderItemModel({
    this.pointName,
    this.pointAddress,
    this.pointTypeName,
    this.areaID,
    this.areaName,
    this.pointStatus,
    this.pointID,
    this.pointLat,
    this.pointLng,
    this.undoReason,
    this.orderID,
    this.pointType,
    this.checkTime,
    this.checkStatus,
  });

  final String pointName;
  final String pointAddress;
  final String pointID;
  final String areaID;
  final String areaName;
  final String orderID;
  final String checkStatus;
  final String pointStatus;
  final String checkTime;
  final String pointLat;
  final String pointLng;
  final String undoReason;

  ///1 特征点 2 设备面
  final String pointType;
  final String pointTypeName;

  static fromJson(json, areaID, areaName) {
    return PatrolOrderItemModel(
      pointName: CommonUtils.checkNullToString(json['ptworkPointname']),
      pointAddress: CommonUtils.checkNullToString(json['ptworkAddress']),
      orderID: CommonUtils.checkNullToString(json['ptworkId']),
      checkStatus: CommonUtils.checkNullToString(json['ptworkResultstatus']),
      pointStatus: CommonUtils.checkNullToString(json['ptworkStatus']),
      checkTime: CommonUtils.checkNullToString(json['ptworkResultdate']),
      pointID: CommonUtils.checkNullToString(json['ptworkPointid']),
      areaName: areaName,
      areaID: areaID,
      pointLat: CommonUtils.checkNullToString(json['pointCoordy']),
      pointLng: CommonUtils.checkNullToString(json['pointCoordx']),
      undoReason: CommonUtils.checkNullToString(json['ptworkContent']),
      pointTypeName: CommonUtils.checkNullToString(json['ptworkPointTypeName']),
      pointType: CommonUtils.checkNullToString(json['ptworkPointType']),
    );
  }

  String get checkStatusStr {
    switch (checkStatus) {
      case '1':
        return '正常';
      case '2':
        return '自修';
      case '3':
        return '隐患';
      case '4':
        return '维修';
      default:
        return '未知';
    }
  }

  String get pointStatusStr {
    switch (pointStatus) {
      case '1':
        return '待巡检';
      case '2':
        return '巡检中';
      case '3':
        return '已完成';
      case '4':
        return '无法巡检';
      default:
        return '未知';
    }
  }

  bool get checked => checkStatus.length != 0;

  bool get hasLngLat => pointLng.length != 0 && pointLat.length != 0;
}
